Calculator
Arrays
- Arrays are like sets, except they can contain duplicates and be ordered in different ways
- They use square brackets, with values separated by commas
[1, 2, 3] [3, 2, 1] [1, 1, 2, 3]
Ranges
- Generate arrays with a start, stop, and optional increment
- Uses the colon character as a separator
- start:stop
- start:increment:stop
1:10 1:0.1:10 10:-1:1 -1:-1:-10 1:2:10 2:2:10
Divides
- Checks if one integer divides another without a remainder
divides(11, 1001) divides(11, 101)
Equiv
- Checks if two numbers are congruent modulo $m$
equiv(a, b, modulus) equiv(12, 15, 3) equiv(13, 15, 3)
Sum
- Computes the sum of a set of numbers
- An optional function can be passed in that is applied to each number before summing
sum(1, 2, 3) sum([1, 2, 3]) sum(1:10) sum([1, 2, 3], f(x) = x * x)
Prod
- Computes the product of a set of numbers
- An optional function can be passed in that is applied to each number before multiplying
prod(1, 2, 3) prod([1, 2, 3]) prod(1:10, f(x) = 1)
Floor
- Rounds a number (or array of numbers) down to the nearest integer
- Optionally takes a second argument, specifying the number of decimal places that should appear in the returned number
- e.g. $\operatorname{floor}(1.55) = 1$
- but $\operatorname{floor}(1.55, 1) = 1.5$
floor(0.5) floor(-0.5) floor([1.5, 2.5]) floor(123.456, 2)
Ceil
- Rounds a number (or array of numbers) up to the nearest integer
- Optionally takes a second argument, specifying the number of decimal places that should appear in the returned number
- e.g. $\operatorname{ceil}(1.55) = 2$
- but $\operatorname{ceil}(1.55, 1) = 1.6$
ceil(0.5) ceil(-0.5) ceil([1.5, 2.5]) ceil(123.456, 2)
Abs
- Caculates the absolute value of a number (or array of numbers)
abs(-0.5) abs(-5:5)
Functions
f(x) = x^2 f(2) f(3) g(a, b) = a + b g(f(2), f(3))
Map
- Applies a function to array elements
map([1, 2, 3], f(x) = 2 * x) g(a) = 1 / a map(1:10, g)